package com.zkadmin.renderer;

import java.util.Set;

import org.zkoss.zul.DefaultTreeNode;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;

import com.zkadmin.entity.SysMenu;

public class RoleMenuTreeitemRenderer extends BaseRenderer implements TreeitemRenderer<DefaultTreeNode<SysMenu>> {
	private Set<SysMenu> roleMenus;

	public RoleMenuTreeitemRenderer(Set<SysMenu> roleMenus) {
		this.roleMenus = roleMenus;
	}

	@Override
	public void render(final Treeitem treeitem, DefaultTreeNode<SysMenu> data, int index) throws Exception {
		SysMenu menu = data.getData();
		if (roleMenus.contains(menu)) {
			treeitem.setSelected(true);
		}

		Treerow treerow = new Treerow();
		treeitem.setAttribute("menuId", menu.getId());
		treeitem.setOpen(true);
		treeitem.appendChild(treerow);

		createTreecell(treerow).setLabel(menu.getName());
		createTreecell(treerow).setLabel(menu.getCode());
	}
}
